package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.analyse.AnalyseNews;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.RegexUtils;
import com.kdtech.utils.StringUtils;

/**
 * <电视台 - 台州电视台> 解析类
 *
 * @author KK
 *
 */
public class _576tvAnalyse implements AnalyseNews {



	
	public boolean isDetailPage(String url) {
		/*
		 * http://v.576tv.com/Program/181105.html
		 */
		String[] regex = {
				"http://.*.576tv.com/Video-[0-9]*.aspx",
				"http://.*.576tv.com/video-[0-9]*.aspx",
				"http://.*.576tv.com/Program/[0-9]*.html",
				};

		return RegexUtils.matchAny(url,regex);
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();

		String title = null;
		Long date = null;
		String desc = null;
		String dateStr = null;
		String clickNum = null;
		Document doc = Jsoup.parse(htmltxt);

		title =   doc.select("div#vBOX2 div.mxx div#pbox div.title").text();
		if (StringUtils.isNullOrEmpty(title)) {
			title = doc.select("h1").text();
		}

		dateStr = doc.select("div#vBOX2 div.mx div.fl div#vifo div.ifo1 div.fl ul li").text();
		if (StringUtils.isNullOrEmpty(dateStr)) {
			dateStr = doc.select("div#vBOX2 div.mx div.fl div#vifo div.ifo1 div.fl ul li").text();
		}

		desc =    doc.select("div#vBOX2 div.mx div.fl div#vifo div.ifo2").text();
		date = DateUtils.matchDate(dateStr);


			if(date==null){
				date = DateUtils.matchDate(doc.select("div#content div.program_hdWrap div.program_hd div.program_titleBar").text());
			}
			desc = doc.select("div.program_bd").text();
			NewsMeta news = new NewsMeta();
			news.setUrl(url);
			news.setType(2);
			news.setTitle(StringUtils.trimSpace(title));

			news.setDate(date);
			news.setContent(StringUtils.trimSpace(desc));
			return news;
	}

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}

	

	
}
